package com.example.springbootdemo.utils;

import org.jasypt.util.text.BasicTextEncryptor;

/**
 * @author xuwangqi
 * @date 2021/5/21 10:01
 * 功能描述：这是一个Jasypt 加密配置文件敏感信息
 **/

public class JasyptUtils {

    /**
     * 加密
     * @param salt 加密用到的盐
     * @param encryptString 加密字符串
     * @return 加密后的encrytSTRING
     */
    public static String encrypt(String salt,String encryptString){
        BasicTextEncryptor encryptor = new BasicTextEncryptor();
        encryptor.setPassword(salt);
        return encryptor.encrypt(encryptString);

    }

    /**
     * 解密
     * @param salt 解密用到的盐，要和加密的盐一致
     * @param dencryptString 解密字符串
     * @return 解密后的denctytString
     */
    public static String dencrypt(String salt,String dencryptString){
        BasicTextEncryptor encryptor = new BasicTextEncryptor();
        encryptor.setPassword(salt);
        return encryptor.decrypt(dencryptString);
    }
}
